package com.pzhu.controller.wx;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.pzhu.model.entity.Thali;
import com.pzhu.model.help.ResponseResult;
import com.pzhu.model.vo.ThaliSwiperVo;
import com.pzhu.service.ThaliService;
import com.pzhu.utils.BeanCopyUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author : zqh
 * @Date : 2023/12/3 0003 下午 5:00
 * @Version: 1.0
 */
@Slf4j
@Api(tags = "小程序用户地址相关的接口")
@RestController
@RequestMapping("/wx/thali")
public class WxThaliController {

    @Autowired
    private ThaliService thaliService;

    @ApiOperation("首页数据")
    @GetMapping("/home")
    public ResponseResult findHomeData() {
        return thaliService.findHomeData();
    }

    @ApiOperation("查找小类别")
    @GetMapping("/findTree/{id}")
    @ApiImplicitParam(name = "id",value = "类别Id",required = true)
    public ResponseResult findTree(@PathVariable(value = "id") Long id){
        return thaliService.findTree(id);
    }

    @ApiOperation("查找所有分类信息")
    @GetMapping("/findAllByTree")
    public ResponseResult findAllByTree(){
        return thaliService.finAllByTree();
    }

    @ApiOperation("查找轮播图")
    @GetMapping("/swiper")
    public ResponseResult findSwiper(){
        List<Thali> thaliList = thaliService.list(new LambdaQueryWrapper<Thali>().eq(Thali::getIsSwiper, true).orderByAsc(Thali::getSort));
        List<ThaliSwiperVo> list = BeanCopyUtils.copyBeanList(thaliList, ThaliSwiperVo.class);
        Map<String, Object> map = new HashMap<>();
        map.put("swiperList",list);
        return ResponseResult.ok(map);
    }

    @ApiOperation("分类详情页")
    @GetMapping("/detail/{id}")
    @ApiImplicitParam(name = "id", value = "套餐ID", required = true)
    public ResponseResult detail(@PathVariable(value = "id") Long id){
        return thaliService.detail(id);
    }
}
